import QtQuick 2.0
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.0
import "storage.js" as Storage

Item {
    id:root
    width: 850
    height: 580
    property real minSize:  Math.min(width/850, height/580)
    property color majorColor: "#44fdfd"

    onFocusChanged:{
        if(!focus) return
        refurbishA()
        refurbishB()
    }

    function readRegSingalLim(handle, sqlName){
        handle.valueText = Storage.readRegSingalLimit(sqlName)
    }
    function writeRegSingalLim(handle, sqlName){
        Storage.writeRegSingalLimit(handle.valueText, sqlName)
    }
    function readRegScope(handle, sqlName){
        handle.tipText = Storage.readRegScope(sqlName)
    }

    function refurbishA()
    {
        readRegSingalLim(text_aVfLimit, "A套VF限制值")
        readRegSingalLim(text_aV1, "A套VF限制值V1")
        readRegSingalLim(text_aV2, "A套VF限制值V2")
        readRegSingalLim(text_aV3, "A套VF限制值V3")
        readRegSingalLim(text_aV4, "A套VF限制值V4")
        readRegSingalLim(text_aV5, "A套VF限制值V5")
        readRegSingalLim(text_aT1, "A套VF限制延时T1")
        readRegSingalLim(text_aT2, "A套VF限制延时T2")
        readRegSingalLim(text_aT3, "A套VF限制延时T3")
        readRegSingalLim(text_aT4, "A套VF限制延时T4")
        readRegSingalLim(text_aT5, "A套VF限制延时T5")
        readRegSingalLim(text_aIntegralC, "A套VF积分时间常数")
        readRegSingalLim(text_aIntegralMin, "A套VF积分最小值")
        readRegSingalLim(text_aIntegralMax, "A套VF积分最大值")
    }
    function refurbishB()
    {
        readRegSingalLim(text_bVfLimit, "B套VF限制值")
        readRegSingalLim(text_bV1, "B套VF限制值V1")
        readRegSingalLim(text_bV2, "B套VF限制值V2")
        readRegSingalLim(text_bV3, "B套VF限制值V3")
        readRegSingalLim(text_bV4, "B套VF限制值V4")
        readRegSingalLim(text_bV5, "B套VF限制值V5")
        readRegSingalLim(text_bT1, "B套VF限制延时T1")
        readRegSingalLim(text_bT2, "B套VF限制延时T2")
        readRegSingalLim(text_bT3, "B套VF限制延时T3")
        readRegSingalLim(text_bT4, "B套VF限制延时T4")
        readRegSingalLim(text_bT5, "B套VF限制延时T5")
        readRegSingalLim(text_bIntegralC, "B套VF积分时间常数")
        readRegSingalLim(text_bIntegralMin, "B套VF积分最小值")
        readRegSingalLim(text_bIntegralMax, "B套VF积分最大值")
    }
    Timer{
        interval: 2000
        repeat: false
        triggeredOnStart: false
        running: true
        onTriggered: {
            readRegScope(text_aVfLimit, "A套VF限制值")
            readRegScope(text_aV1, "A套VF限制值V1")
            readRegScope(text_aV2, "A套VF限制值V2")
            readRegScope(text_aV3, "A套VF限制值V3")
            readRegScope(text_aV4, "A套VF限制值V4")
            readRegScope(text_aV5, "A套VF限制值V5")
            readRegScope(text_aT1, "A套VF限制延时T1")
            readRegScope(text_aT2, "A套VF限制延时T2")
            readRegScope(text_aT3, "A套VF限制延时T3")
            readRegScope(text_aT4, "A套VF限制延时T4")
            readRegScope(text_aT5, "A套VF限制延时T5")
            readRegScope(text_aIntegralC, "A套VF积分时间常数")
            readRegScope(text_aIntegralMin, "A套VF积分最小值")
            readRegScope(text_aIntegralMax, "A套VF积分最大值")
            readRegScope(text_bVfLimit, "B套VF限制值")
            readRegScope(text_bV1, "B套VF限制值V1")
            readRegScope(text_bV2, "B套VF限制值V2")
            readRegScope(text_bV3, "B套VF限制值V3")
            readRegScope(text_bV4, "B套VF限制值V4")
            readRegScope(text_bV5, "B套VF限制值V5")
            readRegScope(text_bT1, "B套VF限制延时T1")
            readRegScope(text_bT2, "B套VF限制延时T2")
            readRegScope(text_bT3, "B套VF限制延时T3")
            readRegScope(text_bT4, "B套VF限制延时T4")
            readRegScope(text_bT5, "B套VF限制延时T5")
            readRegScope(text_bIntegralC, "B套VF积分时间常数")
            readRegScope(text_bIntegralMin, "B套VF积分最小值")
            readRegScope(text_bIntegralMax, "B套VF积分最大值")
        }
    }

    SwipeView
    {
        id: sv_this
        width:parent.width
        height: parent.height*0.85
        clip: true
        Component.onCompleted:{contentItem.highlightMoveDuration = 0}       //将移动时间设为0

        onCurrentIndexChanged: {
            if(sv_this.currentIndex==0) {button.checked=true;button2.checked=false}
            if(sv_this.currentIndex==1) {button2.checked=true;button.checked=false}
        }

        Item{
            Text {
                y: 20*root.minSize
                color: majorColor
                text: qsTr("A通道VF限制参数")
                anchors.horizontalCenter: parent.horizontalCenter
                font.pixelSize: 40*root.minSize
            }

            Rectangle {
                id: rectangle
                y: 70*root.minSize
                width: 800*root.minSize
                height: 400*root.minSize
                color: "#6692e8bc"
                radius: 10*root.minSize
                anchors.horizontalCenter: parent.horizontalCenter

                GridLayout {
                    id: grida
                    width: parent.width*0.96
                    height: parent.height*0.8
                    anchors.left: parent.left
                    anchors.leftMargin: parent.width*0.03
                    flow: GridLayout.TopToBottom
                    rows: 5
                    columns: 3
                    property real textSize: 18*root.minSize


                    EXC_Normal_DoubleTextSytle3 {
                        id:text_aV1
                        Layout.preferredWidth: 160*root.minSize
                        Layout.preferredHeight: 30*root.minSize
                        funcText: qsTr("VF限制值V1:")
                        textSize: parent.textSize
                    }

                    EXC_Normal_DoubleTextSytle3 {
                        id:text_aV2
                        Layout.preferredWidth: 160*root.minSize
                        Layout.preferredHeight: 30*root.minSize
                        funcText: qsTr("VF限制值V2:")
                        textSize: parent.textSize
                    }

                    EXC_Normal_DoubleTextSytle3 {
                        id:text_aV3
                        Layout.preferredWidth: 160*root.minSize
                        Layout.preferredHeight: 30*root.minSize
                        funcText: qsTr("VF限制值V3:")
                        textSize: parent.textSize
                    }

                    EXC_Normal_DoubleTextSytle3 {
                        id:text_aV4
                        Layout.preferredWidth: 160*root.minSize
                        Layout.preferredHeight: 30*root.minSize
                        funcText: qsTr("VF限制值V4:")
                        textSize: parent.textSize
                    }

                    EXC_Normal_DoubleTextSytle3 {
                        id: text_aV5
                        Layout.preferredWidth: 160*root.minSize
                        Layout.preferredHeight: 30*root.minSize
                        textSize: parent.textSize
                        funcText: qsTr("VF限制值V5:")
                    }


                    EXC_Normal_DoubleTextSytle3 {
                        id:text_aT1
                        Layout.preferredWidth: 220*root.minSize
                        Layout.preferredHeight: 30*root.minSize
                        funcText: qsTr("VF限制值延时T1:")
                        textSize: parent.textSize
                    }

                    EXC_Normal_DoubleTextSytle3 {
                        id: text_aT2
                        Layout.preferredWidth: 220*root.minSize
                        Layout.preferredHeight: 30*root.minSize
                        textSize: parent.textSize
                        funcText: qsTr("VF限制值延时T2:")
                    }

                    EXC_Normal_DoubleTextSytle3 {
                        id: text_aT3
                        Layout.preferredWidth: 220*root.minSize
                        Layout.preferredHeight: 30*root.minSize
                        textSize: parent.textSize
                        funcText: qsTr("VF限制值延时T3:")
                    }

                    EXC_Normal_DoubleTextSytle3 {
                        id: text_aT4
                        Layout.preferredWidth: 220*root.minSize
                        Layout.preferredHeight: 30*root.minSize
                        textSize: parent.textSize
                        funcText: qsTr("VF限制值延时T4:")
                    }

                    EXC_Normal_DoubleTextSytle3 {
                        id: text_aT5
                        Layout.preferredWidth: 220*root.minSize
                        Layout.preferredHeight: 30*root.minSize
                        textSize: parent.textSize
                        funcText: qsTr("VF限制值延时T5:")
                    }

                    EXC_Normal_DoubleTextSytle3 {
                        id:text_aIntegralC
                        Layout.preferredWidth: 250*root.minSize
                        Layout.preferredHeight: 30*root.minSize
                        funcText: qsTr("VF限制值积分时间常数:")
                        textSize: parent.textSize
                    }

                    EXC_Normal_DoubleTextSytle3 {
                        id:text_aIntegralMin
                        Layout.preferredWidth: 250*root.minSize
                        Layout.preferredHeight: 30*root.minSize
                        funcText: qsTr("VF限制值积分最小值:")
                        textSize: parent.textSize
                    }

                    EXC_Normal_DoubleTextSytle3 {
                        id:text_aIntegralMax
                        Layout.preferredWidth: 250*root.minSize
                        Layout.preferredHeight: 30*root.minSize
                        funcText: qsTr("VF限制值积分最大值:")
                        textSize: parent.textSize
                    }

                }

                EXC_Normal_DoubleTextSytle3 {
                    id:text_aVfLimit
                    x: 24*root.minSize
                    y: 340*root.minSize
                    width: 160*root.minSize
                    funcText: qsTr("VF限制值:")
                    textSize: grida.textSize
                }
            }

            EXC_Normal_BtnUncheckSecret_highStyle {
                id: btn_ASave
                nameFontpixelSize: 25*root.minSize
                x: 670*root.minSize
                y: 410*root.minSize
                width: 140*root.minSize
                height: 50*root.minSize
                nameText: qsTr("保存参数")

                onClicked: {
                    writeRegSingalLim(text_aVfLimit, "A套VF限制值")
                    writeRegSingalLim(text_aV1, "A套VF限制值V1")
                    writeRegSingalLim(text_aV2, "A套VF限制值V2")
                    writeRegSingalLim(text_aV3, "A套VF限制值V3")
                    writeRegSingalLim(text_aV4, "A套VF限制值V4")
                    writeRegSingalLim(text_aV5, "A套VF限制值V5")
                    writeRegSingalLim(text_aT1, "A套VF限制延时T1")
                    writeRegSingalLim(text_aT2, "A套VF限制延时T2")
                    writeRegSingalLim(text_aT3, "A套VF限制延时T3")
                    writeRegSingalLim(text_aT4, "A套VF限制延时T4")
                    writeRegSingalLim(text_aT5, "A套VF限制延时T5")
                    writeRegSingalLim(text_aIntegralC, "A套VF积分时间常数")
                    writeRegSingalLim(text_aIntegralMin, "A套VF积分最小值")
                    writeRegSingalLim(text_aIntegralMax, "A套VF积分最大值")
                    timerA_ass.start()
                }

                Timer{
                    id:timerA_ass
                    interval: 700
                    repeat: true
                    triggeredOnStart: false
                    property int thisCounter: 0
                    onTriggered: {
                        refurbishA()
                        thisCounter++
                        if(thisCounter>3) {
                            thisCounter=0
                            stop()
                        }
                    }
                }
            }

            onFocusChanged:{
                if(!focus) return
                refurbishA()
            }
        }
        Item{
            Text {
                y: 20*root.minSize
                color: majorColor
                text: qsTr("B通道VF限制参数")
                anchors.horizontalCenter: parent.horizontalCenter
                font.pixelSize: 40*root.minSize
            }

            Rectangle {
                y: 70*root.minSize
                width: 800*root.minSize
                height: 400*root.minSize
                color: "#6692e8bc"
                radius: 10*root.minSize
                anchors.horizontalCenter: parent.horizontalCenter

                GridLayout {
                    id: gridb
                    width: parent.width*0.96
                    height: parent.height*0.8
                    anchors.left: parent.left
                    anchors.leftMargin: parent.width*0.03
                    flow: GridLayout.TopToBottom
                    rows: 5
                    columns: 3
                    property real textSize: 18*root.minSize


                    EXC_Normal_DoubleTextSytle3 {
                        id:text_bV1
                        Layout.preferredWidth: 160*root.minSize
                        Layout.preferredHeight: 30*root.minSize
                        funcText: qsTr("VF限制值V1:")
                        textSize: parent.textSize
                    }

                    EXC_Normal_DoubleTextSytle3 {
                        id:text_bV2
                        Layout.preferredWidth: 160*root.minSize
                        Layout.preferredHeight: 30*root.minSize
                        funcText: qsTr("VF限制值V2:")
                        textSize: parent.textSize
                    }

                    EXC_Normal_DoubleTextSytle3 {
                        id:text_bV3
                        Layout.preferredWidth: 160*root.minSize
                        Layout.preferredHeight: 30*root.minSize
                        funcText: qsTr("VF限制值V3:")
                        textSize: parent.textSize
                    }

                    EXC_Normal_DoubleTextSytle3 {
                        id:text_bV4
                        Layout.preferredWidth: 160*root.minSize
                        Layout.preferredHeight: 30*root.minSize
                        funcText: qsTr("VF限制值V4:")
                        textSize: parent.textSize
                    }

                    EXC_Normal_DoubleTextSytle3 {
                        id: text_bV5
                        Layout.preferredWidth: 160*root.minSize
                        Layout.preferredHeight: 30*root.minSize
                        funcText: qsTr("VF限制值V5:")
                        textSize: parent.textSize
                    }


                    EXC_Normal_DoubleTextSytle3 {
                        id:text_bT1
                        Layout.preferredWidth: 220*root.minSize
                        Layout.preferredHeight: 30*root.minSize
                        funcText: qsTr("VF限制值延时T1:")
                        textSize: parent.textSize
                    }

                    EXC_Normal_DoubleTextSytle3 {
                        id: text_bT2
                        Layout.preferredWidth: 220*root.minSize
                        Layout.preferredHeight: 30*root.minSize
                        textSize: parent.textSize
                        funcText: qsTr("VF限制值延时T2:")
                    }

                    EXC_Normal_DoubleTextSytle3 {
                        id: text_bT3
                        Layout.preferredWidth: 220*root.minSize
                        Layout.preferredHeight: 30*root.minSize
                        textSize: parent.textSize
                        funcText: qsTr("VF限制值延时T3:")
                    }

                    EXC_Normal_DoubleTextSytle3 {
                        id: text_bT4
                        Layout.preferredWidth: 220*root.minSize
                        Layout.preferredHeight: 30*root.minSize
                        textSize: parent.textSize
                        funcText: qsTr("VF限制值延时T4:")
                    }

                    EXC_Normal_DoubleTextSytle3 {
                        id: text_bT5
                        Layout.preferredWidth: 220*root.minSize
                        Layout.preferredHeight: 30*root.minSize
                        textSize: parent.textSize
                        funcText: qsTr("VF限制值延时T5:")
                    }

                    EXC_Normal_DoubleTextSytle3 {
                        id:text_bIntegralC
                        Layout.preferredWidth: 250*root.minSize
                        Layout.preferredHeight: 30*root.minSize
                        funcText: qsTr("VF限制值积分时间常数:")
                        textSize: parent.textSize
                    }

                    EXC_Normal_DoubleTextSytle3 {
                        id:text_bIntegralMin
                        Layout.preferredWidth: 250*root.minSize
                        Layout.preferredHeight: 30*root.minSize
                        funcText: qsTr("VF限制值积分最小值:")
                        textSize: parent.textSize
                    }

                    EXC_Normal_DoubleTextSytle3 {
                        id:text_bIntegralMax
                        Layout.preferredWidth: 250*root.minSize
                        Layout.preferredHeight: 30*root.minSize
                        funcText: qsTr("VF限制值积分最大值:")
                        textSize: parent.textSize
                    }

                }

                EXC_Normal_DoubleTextSytle3 {
                    id:text_bVfLimit
                    x: 24*root.minSize
                    y: 340*root.minSize
                    width: 160*root.minSize
                    funcText: qsTr("VF限制值:")
                    textSize: gridb.textSize
                }
            }

            EXC_Normal_BtnUncheckSecret_highStyle {
                id: btn_BSave
                nameFontpixelSize: 25*root.minSize
                x: 670*root.minSize
                y: 410*root.minSize
                width: 140*root.minSize
                height: 50*root.minSize
                nameText: qsTr("保存参数")
                onClicked: {
                    writeRegSingalLim(text_bVfLimit, "B套VF限制值")
                    writeRegSingalLim(text_bV1, "B套VF限制值V1")
                    writeRegSingalLim(text_bV2, "B套VF限制值V2")
                    writeRegSingalLim(text_bV3, "B套VF限制值V3")
                    writeRegSingalLim(text_bV4, "B套VF限制值V4")
                    writeRegSingalLim(text_bV5, "B套VF限制值V5")
                    writeRegSingalLim(text_bT1, "B套VF限制延时T1")
                    writeRegSingalLim(text_bT2, "B套VF限制延时T2")
                    writeRegSingalLim(text_bT3, "B套VF限制延时T3")
                    writeRegSingalLim(text_bT4, "B套VF限制延时T4")
                    writeRegSingalLim(text_bT5, "B套VF限制延时T5")
                    writeRegSingalLim(text_bIntegralC, "B套VF积分时间常数")
                    writeRegSingalLim(text_bIntegralMin, "B套VF积分最小值")
                    writeRegSingalLim(text_bIntegralMax, "B套VF积分最大值")
                    timerB_ass.start()
                }

                Timer{
                    id:timerB_ass
                    interval: 700
                    repeat: true
                    triggeredOnStart: false
                    property int thisCounter: 0
                    onTriggered: {
                        refurbishB()
                        thisCounter++
                        if(thisCounter>3) {
                            thisCounter=0
                            stop()
                        }
                    }
                }

            }

            onFocusChanged:{
                if(!focus) return
                refurbishB()
            }
        }
    }

    EXC_Normal_BtnSytle {
        id: button
        nameText: qsTr("A通道")
        width: parent.width*0.15
        height: parent.height*0.09
        checked: true
        anchors.left: parent.left
        anchors.leftMargin: parent.width*0.1
        anchors.topMargin: parent.height/32
        anchors.top: sv_this.bottom
        onClicked: {
            if(sv_this.currentIndex==0) checked = true;
            else sv_this.currentIndex = 0
        }
    }

    EXC_Normal_BtnSytle {
        id: button2
        nameText: qsTr("B通道")
        width: parent.width*0.15
        height: parent.height*0.09
        anchors.left: parent.left
        anchors.leftMargin: parent.width*0.43
        anchors.topMargin: parent.height/32
        anchors.top: sv_this.bottom
        onClicked: {
            if(sv_this.currentIndex==1) checked = true;
            else sv_this.currentIndex = 1
        }
    }

    EXC_Normal_BtnUncheckStyle {
        id: button3
        nameText: qsTr("返回")
        nameFontpixelSize: 30*Math.min(root.width/850, root.height/580)
        width: parent.width*0.15
        height: parent.height*0.09
        anchors.left: parent.left
        anchors.leftMargin: parent.width*0.75
        anchors.topMargin: parent.height/32
        anchors.top: sv_this.bottom
        onClicked: {
            sw.currentIndex = 0
        }
    }

}

/*##^##
Designer {
    D{i:0;formeditorZoom:0.8999999761581421}
}
##^##*/
